<template>
  <div>
    {{ msg }}
    {{ itemsModule }}
  </div>
</template>
<script>
import { bus } from '@/main.js';
import { mapState, mapMutations } from 'vuex';
import itemsModule from '../Store/itemsModule';

export default {
  name: 'PlayerBackpack',
  mixins: [], //混入
  components: {
    PlayerSet: () => {
      return import('@/components/玩家装备.vue');
    },
  }, //组件
  props: {}, //集成属性
  data() {
    return {};
  },
  computed: {
    ...mapState(['msg', 'itemsModule']),
  },
  methods: {
    ...mapMutations('itemsModule', {
      // 将模块方法val 映射到 组件中key
      addItem: 'ADD_ITEM',
    }),
    test: function() {
      console.log('test');
      this.addItem({ id: 1, name: '木材' });
      this.addItem({ id: 1, name: '木材' });
      // this.$store.commit('itemsModule/test', { id: 0, name: 'name' });
    },
    formatData: function(type, item) {
      return;
      let _ = this._;
      if (type == '道具类型') {
        let rItem = {
          _id: _.get(item, 'equips_Type_Id', ''), // 道具分类ID
          分类Name: _.get(item, 'remart', ''), //道具名字
          addTime: _.get(item, 'addTime', ''), //入库时间
        };
        // rItem.src = {
        //   1: imgSrc_map,
        //   2: imgSrc_helmet,
        //   3: imgSrc_pokeball,
        // }[rItem._id];
        return rItem;
      }
      // imgSrc_map,
      // imgSrc_helmet,
      // imgSrc_pokeball,
      if (type == '道具') {
        let rItem = {
          _id: _.get(item, 'equips_Id', ''), //主键ID，自增
          分类ID: _.get(item, 'equips_Type_Id', ''), //分类ID
          name: _.get(item, 'equips_Name', ''), //道具名字
          折扣: _.get(item, 'equips_Discount', ''), //道具折扣
          img: _.get(item, 'equips_Img', ''), //道具贴图
          canEquip: _.get(item, 'canEquip', false), //是否可以装备？
          装备部位Id: _.get(item, 'equips_Position_Id', ''), //装备部位，主表：Equips_Position
          价格: _.get(item, 'price', ''), //道具价格（积分）
          canDelete: _.get(item, 'isDelete', false), //是否删除？
          入库时间: _.get(item, 'addTime', ''), //入库时间
          编辑时间: _.get(item, 'editTime', ''), //编辑时间
        };
        // rItem.src = {
        //   1: imgSrc_map,
        //   2: imgSrc_helmet,
        //   3: imgSrc_pokeball,
        // }[rItem.分类ID];
        return rItem;
      }

      return {};
    },
    ajaxData: function(is2p1) {
      let _ = this._;
      return;
      this.$api.玩家角色模块.获取用户角色所有的道具().then((res) => {
        console.log(res);
        if (res.code && res.data) {
          this.a = res.data.map((v) => {
            return this.formatData('道具', v);
          });
        }
      });

      this.$api.玩家角色模块.获取道具所有的分类().then((res) => {
        console.log(res);
        if (res.code && res.data) {
          this.b = res.data.map((v) => {
            return this.formatData('道具类型', v);
          });
        }
      });

      this.$api.道具模块
        .客户道具列表(
          {},
          {
            lastEquipsId: 0, //最后的道具ID
            keyName: '', //关键字
            equipsTypeId: 0, //道具大分类ID
            equipsPositionId: 0, //可装备道具的分类
          }
        )
        .then((res) => {
          console.log(res);
          if (res.code && res.data) {
            this.c = res.data.map((v) => {
              return this.formatData('道具', v);
            });
          }
        });
    },
    try穿戴某装备: function(item, body, slot) {
      //   replaceEquipment(slot, newItem) {
      //     if (slot in this.equipment) {
      //         this.equipment[slot] = newItem;
      //         console.log(`${newItem.name} has been equipped to ${slot}.`);
      //     } else {
      //         console.log(`Invalid equipment slot: ${slot}`);
      //     }
      // }
    },
  },
  beforeCreate: function() {},
  created: function() {},
  beforeMount: function() {},
  mounted: function() {
    // this.ajaxData();
    this.$store.commit('setValue', { key: 'msg', value: 1 });
    this.test();
    // this.$store.commit('itemsModule/ADD_ITEM', { id: 0, name: 'name' });
  },
  beforeUpdate: function() {},
  updated: function() {},
  beforeDestroy: function() {},
  destroyed: function() {},
};
</script>
<style lang="less" scoped></style>
